package com.ihr360.excel.service.convertor;

import com.google.common.collect.Lists;
import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.excel.entity.SpreadsheetJournalEntity;
import com.ihr360.excel.model.dto.SpreadsheetJournal;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SpreadsheetJournalConvertor implements IConvertor<SpreadsheetJournalEntity, SpreadsheetJournal> {
    @Override
    public SpreadsheetJournal convertEntityToDto(SpreadsheetJournalEntity entity) {
        return null;
    }

    @Override
    public SpreadsheetJournalEntity convertDtoToEntity(SpreadsheetJournal dto) {
        if (dto == null) {
            return null;
        }
        SpreadsheetJournalEntity entity = new SpreadsheetJournalEntity();
        BeanUtils.copyProperties(dto, entity);
        return entity;
    }

    public List<SpreadsheetJournalEntity> convertDtosToEntities(List<SpreadsheetJournal> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Lists.newArrayList();
        }
        List<SpreadsheetJournalEntity> entities = Lists.newArrayListWithCapacity(dtos.size());
        for (SpreadsheetJournal dto : dtos) {
            entities.add(convertDtoToEntity(dto));
        }
        return entities;
    }


}
